package com.ming.easyDevelop.entity.query.base;

import com.ming.easyDevelop.entity.baseEnum.PageSize;
public class SimplePage {
    private int pageNo;
    private int pageSize;
    private int pageTotal;
    private int start;
    private int end;
    private int countTotal;

    public SimplePage() {
    }

    public SimplePage(Integer start, Integer end) {
        this.start = start;
        this.end = end;
    }

    public SimplePage(Integer pageNo, Integer pageSize, Integer countTotal) {
        if(null == pageNo) pageNo = 0;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.countTotal = countTotal;
    }

    public void action(){
        if (this.pageNo <= 0) this.pageNo = PageSize.SIZE20.getSize();
        if (this.countTotal > 0) this.pageTotal = this.countTotal % pageSize == 0 ? this.countTotal / this.pageSize : this.countTotal / pageSize + 1;
        else this.pageTotal = 1;

        if(this.pageNo <= 1) pageNo = 1;
        if (this.pageNo > this.pageTotal) this.pageNo = this.pageTotal;
        this.start = (pageNo - 1) * pageSize;
        this.end = this.pageSize;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageTotal() {
        return pageTotal;
    }

    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    public int getCountTotal() {
        return countTotal;
    }

    public void setCountTotal(int countTotal) {
        this.countTotal = countTotal;
    }
}
